package com.sdkj.recruit.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sdkj.recruit.dao.ILabelDao;
import com.sdkj.recruit.model.Label;
import com.sdkj.recruit.model.ResultCode;
import com.sdkj.recruit.model.ResultData;
import com.sdkj.recruit.service.ILabelService;
import com.sdkj.recruit.vo.LabelVo;

@Service
public class LabelService implements ILabelService{

	@Autowired
	private ILabelDao labelDao;
	
	@Autowired
	private Mapper mapper;
	@Override
	public ResultData<Object> saveLabel(Label label) {
		labelDao.saveLabel(label);
		return ResultCode.success("新增标签成功", null);
	}
	@Override
	public void deleteLabel(String labelId) {
		labelDao.deleteLabel(labelId);
	}
	@Override
	public List<LabelVo> queryLabelList(int pageNo, int pageSize, String keyWord) {
		List<LabelVo> list = new ArrayList<LabelVo>();
		List<Label> LabelList = labelDao.queryLabelList(pageNo, pageSize, keyWord);
		if (CollectionUtils.isNotEmpty(LabelList)) {
			for (Label label : LabelList) {
				LabelVo vo = mapper.map(label, LabelVo.class);
				list.add(vo);
			}
		}
		return list;
	}
	@Override
	public long queryAllLabelCount(String keyWord) {
		return labelDao.queryAllLabelCount(keyWord);
	}
	@Override
	public LabelVo queryLableByName(String labelName) {
		Label label = labelDao.queryLableByName(labelName);
		return label==null?null :mapper.map(label, LabelVo.class);
	}

}
